home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / misc / sstrings.c < prev    next >
C/C++ Source or Header  |  1995-10-14  |  730b  |  48 lines

  1. #include "misc.h"
  2.  
  3. PUBLIC SSTRING *SSTRINGS::getitem (int no) const
  4. {
  5.     return (SSTRING *)ARRAY::getitem(no);
  6. }
  7.  
  8. static int cmp (ARRAY_OBJ *o1, ARRAY_OBJ *o2)
  9. {
  10.     SSTRING *s1 = (SSTRING *)o1;
  11.     SSTRING *s2 = (SSTRING *)o2;
  12.     return s1->cmp(*s2);
  13. }
  14.  
  15. /*
  16.     Sort the array of SSTRING
  17. */
  18. PUBLIC void SSTRINGS::sort ()
  19. {
  20.     ARRAY::sort (cmp);
  21. }
  22.  
  23.  
  24. /*
  25.     Find the occurence of a string in the array.
  26.     Return -1 if not found or the index if found
  27. */
  28. PUBLIC int SSTRINGS::lookup(const char *str) const
  29. {
  30.     int ret = -1;
  31.     int nb = getnb();
  32.     for (int i=0; i<nb; i++){
  33.         SSTRING *s = getitem(i);
  34.         if (s->cmp(str)==0){
  35.             ret = i;
  36.             break;
  37.         }
  38.     }
  39.     return ret;
  40. }
  41.  
  42. PUBLIC int SSTRINGS::lookup(const SSTRING *str) const
  43. {
  44.     return lookup (str->get());
  45. }
  46.  
  47.  
  48.